#include "showtextwindow.h"
#include <QPainter>
#include <QGuiApplication>
#include <QScreen>


/**
 * @brief ShowTextWindow::ShowTextWindow
 * @param parent
 * 显示界面的文本区域
 */


ShowTextWindow::ShowTextWindow(QWidget *parent)
    : QWidget(parent)
{
    setupUI();
}

void ShowTextWindow::setupUI()
{
    setWindowFlags(Qt::FramelessWindowHint);
    setAttribute(Qt::WA_TranslucentBackground);

    QScreen *screen = QGuiApplication::primaryScreen();
    fullScreenPixmap = screen->grabWindow(0);
    resize(fullScreenPixmap.size());
}

void ShowTextWindow::setRectangles(const QVector<QVector<int>>& rects)
{
    rectangles = rects;
    update(); // 通知窗口需要重新绘制
}

void ShowTextWindow::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);
    QPainter painter(this);

    painter.drawPixmap(0, 0, fullScreenPixmap);

    QPen pen;
    pen.setColor(Qt::green); // 设置线的颜色为绿色
    pen.setWidth(5);
    painter.setPen(pen); // 设置矩形框的颜色
    for (const QVector<int>& rectCoords : rectangles) {
        if (rectCoords.size() == 8) {
            int x1 = rectCoords[0];
            int y1 = rectCoords[1];
            int x2 = rectCoords[2];
            int y3 = rectCoords[5];
            // 绘制矩形框
            painter.drawRect(x1, y1, x2 - x1, y3 - y1);
        }
    }

}

void ShowTextWindow::updateTextWindow()
{
    update();
}


ShowTextWindow::~ShowTextWindow()
{
}

